﻿using System;
using System.Collections;
using System.Data;
using System.Reflection;

namespace WeiSha.Core.Tree
{
	// Token: 0x02000032 RID: 50
	public class ObjectArrayToDataTable
	{
		// Token: 0x060001D1 RID: 465 RVA: 0x0000D6D8 File Offset: 0x0000B8D8
		public static DataTable To(Array arr)
		{
			bool flag = arr.Length < 1;
			DataTable dataTable;
			if (flag)
			{
				dataTable = null;
			}
			else
			{
				DataTable dataTable2 = new DataTable();
				dataTable2.Columns.Add(new DataColumn("Tree", typeof(string)));
				dataTable2.Columns.Add(new DataColumn("isTop", typeof(bool)));
				dataTable2.Columns.Add(new DataColumn("isDown", typeof(bool)));
				var enumerator = arr.GetEnumerator();
				if (enumerator.MoveNext())
				{
					object obj = enumerator.Current;
					Type type = obj.GetType();
					foreach (PropertyInfo propertyInfo in type.GetProperties())
					{
						Type underlyingType = Nullable.GetUnderlyingType(propertyInfo.PropertyType);
						string text = ((underlyingType != null) ? underlyingType.Name : propertyInfo.PropertyType.Name);
						bool flag2 = propertyInfo.PropertyType.ToString() == "System.Nullable" || text.IndexOf("`") > -1;
						if (flag2)
						{
							dataTable2.Columns.Add(new DataColumn(propertyInfo.Name, typeof(string)));
						}
						else
						{
							dataTable2.Columns.Add(new DataColumn(propertyInfo.Name, propertyInfo.PropertyType));
						}
					}
				}
				foreach (object obj2 in arr)
				{
					DataRow dataRow = dataTable2.NewRow();
					Type type2 = obj2.GetType();
					foreach (PropertyInfo propertyInfo2 in type2.GetProperties())
					{
						dataRow[propertyInfo2.Name] = type2.GetProperty(propertyInfo2.Name).GetValue(obj2, null);
					}
					dataTable2.Rows.Add(dataRow);
				}
				dataTable = dataTable2;
			}
			return dataTable;
		}
	}
}
